const Controllers = require('../controllers/index');
const validate = require('../middlewares/validate');

const routes = [
  {
    // 登录
    path: '/login',
    method: 'post',
    validate: validate({
      'username': 'required|min:3|max:30',
      'password': 'required',
    }),
    controller: Controllers.login
  },
  {
    // 菜单列表
    path: '/api/getMenuList',
    method: 'get',
    validate: validate({
      'pageNum': 'required|number',
      'pageSize': 'required|number',
    }),
    controller: Controllers.getMenuList
  },
  {
    // 修改菜单
    path: '/api/saveMenu',
    method: 'post',
    validate: validate({
      'id': 'required|number',
    }),
    controller: Controllers.saveMenu
  },
  {
    // 用户列表
    path: '/api/getAdminList',
    method: 'get',
    validate: validate({
      'pageNum': 'required|number',
      'pageSize': 'required|number',
    }),
    controller: Controllers.getAdminList
  },
  {
    // 添加用户
    path: '/api/addAdmin',
    method: 'post',
    validate: validate({
      'username': 'required|min:3|max:30',
      'group_id': 'required',
      'mobile': 'required',
      'realname': 'required|string'
    }),
    controller: Controllers.addAdmin
  },
  {
    // 编辑用户
    path: '/api/updateAdmin',
    method: 'post',
    validate: validate({
      'username': 'required|min:3|max:30',
      'group_id': 'required',
      'mobile': 'required',
      'realname': 'required|string'
    }),
    controller: Controllers.updateAdmin
  },
  {
    // 角色列表
    path: '/api/getGroupList',
    method: 'get',
    validate: validate({
      'pageNum': 'required|number',
      'pageSize': 'required|number',
    }),
    controller: Controllers.getGroupList
  },
  {
    // 添加角色
    path: '/api/addGroup',
    method: 'post',
    validate: validate({
      'title': 'required|string|max:30',
      'rules': 'required',
    }),
    controller: Controllers.addGroup
  },
  {
    // 修改角色权限
    path: '/api/saveGroupRule',
    method: 'post',
    validate: validate({
      'id': 'required|number',
    }),
    controller: Controllers.saveGroupRule
  },
  {
    // 权限列表
    path: '/api/getRuleList',
    method: 'get',
    validate: validate({
      'pageNum': 'required|number',
      'pageSize': 'required|number',
    }),
    controller: Controllers.getRuleList
  },
  {
    // 查询菜单下的权限
    path: '/api/ruleAuthFindById',
    method: 'get',
    validate: validate({
      'id': 'required',
    }),
    controller: Controllers.ruleAuthFindById
  },
  {
    // 更新权限
    path: '/api/updateRule',
    method: 'post',
    validate: validate({
      'id': 'required',
      'title': 'required|string'
    }),
    controller: Controllers.updateRule
  },
  {
    // 添加权限
    path: '/api/addRule',
    method: 'post',
    validate: validate({
      'title': 'required|string'
    }),
    controller: Controllers.addRule
  },
  {
    // 查看角色权限
    path: '/api/getGroupRuleList',
    method: 'get',
    validate: validate({
      'id': 'required'
    }),
    controller: Controllers.getGroupRuleList
  },
  {
    // 删除权限
    path: '/api/deleteRule',
    method: 'get',
    validate: validate({
      'id': 'required',
    }),
    controller: Controllers.deleteRuleById
  },
  {
    // 删除管理员
    path: '/api/deleteAdmin',
    method: 'get',
    validate: validate({
      'id': 'required',
    }),
    controller: Controllers.deleteAdminById
  },
  {
    // 删除角色
    path: '/api/deleteGroup',
    method: 'get',
    validate: validate({
      'id': 'required',
    }),
    controller: Controllers.deleteGroupById
  },
  {
    // 修改账号密码
    path: '/api/updateAdminPassword',
    method: 'post',
    validate: validate({
      'id': 'required',
      'password': 'required',
    }),
    controller: Controllers.updateAdminPassword
  },
]

module.exports = routes;